<!--&#45;&#45;chongzhi-->
<!-- 首页 -->
<template>
	<view class="home-wrap u-m-b-20" :style="{background: '#FAFAFBFF url(https://d-shenhuashop.bigchun.com/h5test/yuanbao/chongzhi/beijing.png) no-repeat','background-size': '100%','height':'100vh'}">
		<wanl-navbar :isBack="true"
		             :background="{background:'url(https://d-shenhuashop.bigchun.com/h5test/yuanbao/chongzhi/beijing.png) no-repeat','background-size': '100% 100%'}"
		             :showGongNeng="true"
		             :gongnengColor="'#fff'"
		             :backIconColor="'#fff'"
		>
			<text
				slot="content"
				style="color: #fff; width: 100%; text-align: center;padding-left: 20rpx;font-size:30rpx"
			>
				                {{'金元宝充值'}}
			</text>
		</wanl-navbar>
		<view class="content-box u-p-10 u-m-l-20 u-m-r-20">
			<view class="chongzhi_top" style="position: relative">
				<view class="yuanbao"></view>
				<view class="shengyu">剩余金元宝(个): {{ removeTrailingZeros(yuanbao) }}</view>
				<view @click="$wanlshop.to(`/pages/apps/jinyuanbao/chongzhi/mingxi`)" style="padding: 10rpx 20rpx;position: absolute; top: -56rpx;right: 0rpx;color: #fff">金元宝明细</view>
			</view>
<!--			<view class="chongzhi_content">-->
<!--				<view class="chongzhi_title">充值数量</view>-->
<!--				<view class="chongzhi_group">-->
<!--					<view class="chongzhi_item" v-for="(item,index) in chongzhiList" :class="currentIndex!=='' &&  currentIndex == index ?'active':''" @click="chooseOne(item,index)">-->
<!--						<view>{{removeTrailingZeros(item.name)}}个</view>-->
<!--						<view>{{removeTrailingZeros(item.money)}}元</view>-->
<!--					</view>-->
<!--				</view>-->
<!--				-->
<!--			</view>-->
			
			<view class="item items" style="margin: 60rpx 20rpx 0;padding: 0 8rpx 0 30rpx;border-radius:20rpx;background:#fff">
				<view class="action" style="display: flex;justify-content: space-between;
					align-items: center;
					flex-direction: row;">
					<view style="display: flex;flex-direction: column;justify-content: flex-start;">
						<text class="title wanl-pip">{{'神话app会员账号'}}</text>
					</view>
					<view style="width: 66%;background: #fff; border-radius: 16rpx;padding: 20rpx 20rpx;display: flex;
    justify-content: center;
    align-items: center;
    color: #999;
	font-size: 30rpx">
						<u-input
							style="margin-right: 10rpx"
							border="none"
							placeholder="请输入神话app会员账号"
							inputAlign="right"
							v-model="account"
							fontSize="16"
						></u-input>
					</view>
				</view>
			
			</view>
			<view class="item items" style="margin: 30rpx 20rpx 60rpx;padding: 0 8rpx 0 30rpx;border-radius:20rpx;background:#fff">
				<view class="action" style="display: flex;justify-content: space-between;
					align-items: center;
					flex-direction: row;">
					<view style="display: flex;flex-direction: column;justify-content: flex-start">
						<text class="title wanl-pip">{{'充值数量'}}</text>
					</view>
					<view style="width: 70%;background: #fff; border-radius: 16rpx;padding: 20rpx 20rpx;display: flex;
    justify-content: center;
    align-items: center;
    color: #999;
	font-size: 30rpx">
						<u-input
							style="margin-right: 10rpx"
							border="none"
							placeholder=""
							inputAlign="right"
							v-model="jinYuanBaoValue"
							fontSize="16"
						></u-input>个
					</view>
				</view>
			
			</view>
			<view class="chongzhi_tishi">
				<view class="waring" style="width: 30rpx;height: 30rpx; margin-right:10rpx" mode="widthFix" ></view>
				<text>温馨提示:充值后不可退款，请您确认后充值！</text>
			</view>
			<button class="u-reset-button login-btn-start" @tap="gochongzhi()">
					去充值
			</button>
		</view>
		<wanl-modal custom :show="attendanceModalVisible">
			<view class="attendance-modal">
				<view class="modal-header">
<!--					<image :src="$wanlshop.appstc('/common/cup.png')" mode="widthFix"></image>-->
				</view>
				<view class="modal-content text-sm wanl-gray" style="font-size: 30rpx;color:#333333;text-align: justify;line-height: 48rpx">
					<view>{{ `请在神话 APP 转账${jinYuanBaoValue}金元宝至${phoneConfig}` }}</view>
				</view>
				<view class="modal-btn" style="    display: flex;
    justify-content: center;"><button class="cu-btn wanl-bg-redorange round lg text-sm" style="    width: 80%;
    margin: 20px 0 0 0;" @tap="attendanceModalVisible = false;creatOrder()">我知道了</button></view>
			</view>
		</wanl-modal>
	</view>
</template>

<script>

import {mapMutations, mapActions, mapState, mapGetters} from 'vuex';

let chart = null
export default {
	data() {
		return {
			chongzhiList:[
			],
			currentIndex:'',
			money:'',
			money_id:'',
			yuanbao:'',
			jinYuanBaoValue:'',
			account:'',
			attendanceModalVisible:false,
			phoneConfig:'',
			lock:true
		};
	},
	computed: {
	},
	onPullDownRefresh() {
	
	},
	
	onShow() {
		this.getConfig();
		this.init();
	},
	onHide() {
	
	},
	methods: {
		removeTrailingZeros(num) {
			return Number(num.replace(/\.?0+$/, ''));
		},
		// 初始化
		init() {
			this.initdata()
		},
		denglu() {
			this.$store.dispatch("showAuthModal", "1233")
		},
		initdata(){
			let that = this;
			uni.request({
				url:'/wanlshop/user/profile',
				method: 'POST',
				data:{
				},
				success:(res)=>{
					console.log("===信息。",res);
					this.yuanbao = res.data.yuanbao;
					uni.setStorageSync("yuanbao",res.data.yuanbao)
				}
			});
			uni.request({
				url:'/wanlshop/user/recharge_lists',
				method: 'POST',
				data:{
				},
				success:(res)=>{
					that.chongzhiList = res.data;
				}
			});
		},
		chooseOne(item,index){
			this.currentIndex = index;
			this.money = this.removeTrailingZeros(item.money);
			this.money_id = item.id;
			this.yuanbao_num = this.removeTrailingZeros(item.name);
		},
		gochongzhi(){
			let that = this;
			if(that.account){
				if(that.jinYuanBaoValue){
					that.attendanceModalVisible=true;
				}else {
					uni.showToast({
						title:'请选择充值金额',
						icon:'none'
					})
				}
			}else{
				uni.showToast({
					title:'请输入神话App会员账号',
					icon:'none'
				})
			}
		},
		creatOrder(){
			var that = this;
			if(that.lock){
				that.lock = false;
				uni.request({
					url:'/wanlshop/user/new_recharge',
					method: 'POST',
					data:{
						// money:this.money,
						money:that.jinYuanBaoValue,
						phone:that.account
					},
					success:(res)=>{
						if(res.res.code) {
							uni.showToast({
								title:res.res.msg,
								icon:'none'
							})
							that.lock = true;
							that.jinYuanBaoValue = "";
							that.account = "";
						}	else{
							uni.showToast({
								title:"订单创建失败",
								icon:'none'
							})
							that.lock = true;
						}				// that.$wanlshop.to(`/pages/apps/jinyuanbao/generateTwoDimensionalCode?money=${that.money}&order_id=${res.data.order_no}&user_id=${uni.getStorageSync("wanlshop:user").id}&path=${res.data.path}&yuanbao_num=${that.yuanbao_num}`)
					}
				});
			}
			
			
		},
		getConfig(){
			var that = this;
			uni.request({
				url:'/wanlshop/user/config',
				method: 'POST',
				success:(res)=>{
					that.phoneConfig = res.data.phone
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.home-wrap{
	background:rgba(250, 250, 251, 1);
}
.uni-ec-canvas {
	width: 100%;
	height: 400rpx;
	display: block;
}
.uni-ec-canvas-bing {
	width: 100%;
	height: 200rpx;
	display: block;
}
page {
	background: #FAFAFB;
}
.login-btn-start {
	width: 90%;
	margin: 30rpx auto 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	height: 86rpx;
	background: linear-gradient(90deg, #FC6A24, #FC6A24);
	border-radius: 38rpx;
	font-size: 26rpx;
	font-weight: 500;
	color: #ffffff;
	position: fixed;
	bottom: 60rpx;
	left: 4.5%;
}
.chongzhi_top{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	margin-top: 80rpx;
	
	.yuanbao{
		width: 180rpx;
		height: 180rpx;
		margin-bottom: 40rpx;
		background: url("https://d-shenhuashop.bigchun.com/h5test/yuanbao/chongzhi/yuanbao.png") no-repeat center;
		background-size: 100%;
	}
	.shengyu{
		color:#fff;
		font-size: 34rpx;
	}
}
.chongzhi_content{
	width: 95%;
	height: 440rpx;
	margin: 60rpx auto;
	background: #fff url('/images/chongzhi/chongzhi.png') no-repeat center;
	background-size: 100%;
	border-radius: 30rpx;
	background-position-y: 0;
	overflow: hidden;
	padding: 20rpx;
	.chongzhi_group{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		align-items: center;
		margin-top: 20rpx;
		.chongzhi_item{
			width: 30%;
			background: #F6F6F6;
			border-radius: 20rpx;
			color: #666666;
			padding: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			margin-top: 20rpx;
			font-size: 34rpx;
			border: 1rpx solid transparent;
		}
		.active{
			background: #F9E8E0;
			color: #FF6121;
			border: 1rpx solid #FD6B25;
		}
	}
	.chongzhi_title{
		margin-top: 20rpx;
		padding-left: 20rpx;
		font-size: 34rpx;
	}
}
.chongzhi_tishi{
	width: 95%;
	background: #F9E8E0;
	border-radius: 18rpx;
	padding: 30rpx 30rpx;
	color: #FF6121;
	margin: 0 auto;
	display: flex;
	justify-content: flex-start;
	align-items: center;
}
.waring{
	background: url("https://d-shenhuashop.bigchun.com/h5test/yuanbao/chongzhi/jinggao.png") no-repeat center;
	background-size: 100%;
}
</style>
